<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        //1.创建json格式
        const jsonStr1 = '{"username":"zhangsan","age":"20" }'  //格式只能这样

        const jsonStr2 = {
            "username":"zhangsan",
            "age":"20"
        }



        //1.创建一个对象
        const obj = {
            username:"张三",
            age:20,
            gender:"男"
        }

        //将对象转换为json字符串
        console.log(obj)
        const objStr = JSON.stringify(obj)
        console.log(objStr)

        //将json字符串转换为对象
        console.log("-------------")
        console.log(jsonStr)
        const jsonObj = JSON.parse(jsonStr)
        console.log(jsonObj)



    </script>
</body>
</html>